<style lang="less">
	page{
		background: #f6f6f6;
	}
	.content {
		text-align: center;
		min-height: 100%;
		padding-bottom: 100upx;
	}
    .main_list{
    }
    .item_list{
    	width: 100%;
		background: #FFFFFF;
		padding: 20upx 30upx;
		box-sizing: border-box;
		overflow: hidden;
		margin-top: 20upx;
		.item_list_cent_fl{
			float: left;
			width: 80%;
			text-align: left;
			.title{
				font-size:28upx;
				color:rgba(51,51,51,1);
				line-height:42upx;
			}
			.cent_content{
				text-align: left;
				font-size:24upx;
				color:rgba(153,153,153,1);
				line-height:36upx;
				margin-top: 20upx;
				overflow:hidden;
				text-overflow:ellipsis;
				display:-webkit-box;
				-webkit-box-orient:vertical;
				-webkit-line-clamp:2;
			}
		}
		.item_list_cent_fr{
			float: right;
			width: 20%;
			text-align: right;
			.status{
				font-size:26upx;
				color:rgba(219,193,145,1);
				line-height:42upx;
			}
			.amount{
				font-size:30upx;
				font-family:'DINCond';
				font-weight:400;
				margin-top: 30upx;
				color:rgba(51,51,51,1);
				line-height:48upx;
			}
		}
    }
	
	.check-box {
	  display: flex;
	  justify-content: space-between;
	  position: fixed;
	  left: 0;
	  bottom: 0;
	  width: 100%;
	  height: 98upx;
	  background:rgba(7,5,6,1);
	  z-index: 999;
	  .pay-btn {
	    width: 100%;
	    text-align: center;
	    background:rgba(7,5,6,1);
	    color: #ffffff;
		line-height: 98upx;
	    font-size: 30upx;
	  }
	}
	//活动规则
	 .guize{
	   position: fixed;
	   z-index: 101;
	   right: 0;
	   top: 30%;
	   line-height: 60upx;
	   background: #ffffff;
	   color: #ffffff;
	   width: 150upx;
	   text-align: center;
	   font-size: 28upx;
	   border-radius: 30upx 0 0 30upx;
	   overflow: hidden;
	   view{
	     opacity: 0.2;
	     background: #000000;
	   }
	 }
	 //活动规则展开
	 .guize-pos{
	   position: fixed;
	   width: 100%;
	   height: 100%;
	   z-index: 1000;
	   left: 0;
	   top: 0;
	   .guize-pos-bj{
	     position: absolute;
	     left: 0;
	     top: 0;
	     z-index: 1001;
	     background: #000000;
	     opacity: 0.3;
	     width: 100%;
	     height:100%;
	   }
	   .guize-pos-centent{
	     width: 560upx;
	     height: 560upx;
	     background:rgba(255,255,255,1);
	     border-radius:24upx;
	      position: absolute;
	      z-index: 1002;
	      left: 50%;
	      top: 50%;
	      margin: -280upx 0 0 -280upx;
	      box-sizing: border-box;
	      padding: 45upx;
	      .centent{
	        color:rgba(51,51,51,1);
	        max-height: 480upx;
			view{
				font-size:28upx;
				line-height:44upx;
			}
	      }
	      .close{
	        position: absolute;
	        width: 60upx;
	        height: auto;
	        bottom: -80upx;
	        left: 50%;
	        margin-left: -30upx;
	        z-index: 1003;
	      }
	   }
	 }
</style>
<template>
	<view>
			<segmented-control
			  id="tabbar"
			  :values="items"
			  :stickyTop="0"
			  :current="current"
			  @clickItem="onClickItem"
			></segmented-control>
			<!-- <view class="list" id="list">{{ current }}</view> -->
		<!-- 	<view class="uni-padding-wrap uni-common-mt">
				<uni-segmented-control :current="current" :stickyTop="108" :values="items" :style-type="styleType" :active-color="activeColor" @clickItem="onClickItem" />
			</view> -->
			<view class="content">
				<view v-show="current === 0">
					<view class="main_list">
						<view class="item_list" v-for="(itme,i) in list" @tap="obj(itme.id)">
							<view class="item_list_cent_fl">
								<view class="title">{{itme.title}}</view>
								<view class="cent_content">{{itme.content}}</view>
							</view>
							<view class="item_list_cent_fr">
								<view class="status" v-if="itme.status == 1">申请中</view>
								<view class="status" v-else-if="itme.status == 2">申请成功</view>
								<view class="status" v-else-if="itme.status == 3">申请失败</view>
								<view class="amount">¥ {{itme.amount}}</view>
							</view>
						</view>
					</view>
				</view>
				<view v-show="current === 1">
					<view class="main_list">
						<view class="item_list" v-for="(itme,i) in listOne" @tap="obj(itme.id)">
							<view class="item_list_cent_fl">
								<view class="title">{{itme.title}}</view>
								<view class="cent_content">{{itme.content}}</view>
							</view>
							<view class="item_list_cent_fr">
								<view class="status" v-if="itme.status == 1">申请中</view>
								<view class="status" v-else-if="itme.status == 2">申请成功</view>
								<view class="status" v-else-if="itme.status == 3">申请失败</view>
								<view class="amount">¥ {{itme.amount}}</view>
							</view>
						</view>
					</view>
				</view>
				<view v-show="current === 2">
					<view class="main_list">
						<view class="item_list" v-for="(itme,i) in listTwo" @tap="obj(itme.id)">
							<view class="item_list_cent_fl">
								<view class="title">{{itme.title}}</view>
								<view class="cent_content">{{itme.content}}</view>
							</view>
							<view class="item_list_cent_fr">
								<view class="status" v-if="itme.status == 1">申请中</view>
								<view class="status" v-else-if="itme.status == 2">申请成功</view>
								<view class="status" v-else-if="itme.status == 3">申请失败</view>
								<view class="amount">¥ {{itme.amount}}</view>
							</view>
						</view>
					</view>
				</view>
				<view v-show="current === 3">
					<view class="main_list">
						<view class="item_list" v-for="(itme,i) in listThree" @tap="obj(itme.id)">
							<view class="item_list_cent_fl">
								<view class="title">{{itme.title}}</view>
								<view class="cent_content">{{itme.content}}</view>
							</view>
							<view class="item_list_cent_fr">
								<view class="status" v-if="itme.status == 1">申请中</view>
								<view class="status" v-else-if="itme.status == 2">申请成功</view>
								<view class="status" v-else-if="itme.status == 3">申请失败</view>
								<view class="amount">¥ {{itme.amount}}</view>
							</view>
						</view>
					</view>
				</view>
				<view class="uni-loadmore" v-if="showLoadMore">{{loadMoreText}}</view>
			</view>
			<view class="guize" @tap.stop="guizeShow"><view>活动规则</view></view>
			<view class="guize-pos" v-if="gzShow==true">
			  <view class="guize-pos-bj"></view>
			  <view class="guize-pos-centent">
			    <scroll-view scroll-y="true" class="centent" v-if="centerGz != null"><!-- {{centerGz.content}} -->
					<view v-html="centerGz.content"></view>
			    </scroll-view>
			    <image src="https://xpandago.oss-cn-shanghai.aliyuncs.com/wechat/images/closed_boxs%402x.png" @tap.stop="guizeHide" class="close" mode="widthFix"></image>
			  </view>
			</view>
			<view class="check-box">
			  <view class="pay-btn" @tap="add">申请补贴</view>
			</view>
	</view>
</template>

<script>
	import api from '@/common/api';
	import segmentedControl from '@/components/control/segmented-control';
	export default {
		components: {
			segmentedControl
		},
		data() {
			return {
				list:[],
				listOne:[],
				listTwo:[],
				listThree:[],
				dataTop: {},
				current: 0,
				centerGz:'',
				items: [
					'全部',
					'申请中',
					'申请成功',
					'申请失败'
				],
				loadMoreText: "加载中...",
				gzShow:false,
				showLoadMore: false,
				totalPage:'',//总页数
				page:1,
				token:''
			}
		},
		onShow(){
			this.page=1
			this.list=[]
			this.token=uni.getStorageSync('token')
			console.log(this.token)
			let code=this.GetQueryString('code');
			console.log(code)
			var pages = getCurrentPages(); // 当前页面
			var beforePage = pages[pages.length - 1]; // 获取当前页面的对象
			var url = beforePage.route //当前页面url
			uni.setStorageSync('url', url);
			console.log(url)
			if(this.token!=null && this.token !='' && this.token != undefined){
				this.allowanceList(this.page)
			}else if(code!=null && code !='' && code != undefined){
				this.loginCode(code)
			}else{
				uni.showToast({
					title: '请先登录！',
					icon: 'none'
				})
				setTimeout(() => {
					uni.reLaunch({
					  url: "/pages/login/loginWechat"
					})
				}, 1000);
			}
		},
		onLoad() {
			
		},
		onReachBottom() {
			console.log(this.page)
			console.log('totalPage',this.totalPage)
			this.showLoadMore = true;
			if (this.page >= this.totalPage) {
				this.loadMoreText = "没有更多数据了!"
				return;
			}else{
				this.page++
				setTimeout(() => {
					this.allowanceList(this.page)
				}, 1000);
			}
		},
		methods: {
			async loginCode(code){
				const [err, res] = await api.loginCode({
						query: {
							code:code
						}
					 });
				 console.log(res)
				 if(res.data.code == 0){
					 let token=res.data.data
					 this.token=token
					 uni.setStorageSync('token', token);
					 this.allowanceList(this.page)
				 }else{
					 uni.showToast({
					 	title: res.data.msg,
					 	icon: 'none'
					 })
					if(res.data.code==100){
						uni.removeStorageSync('token');
						setTimeout(() => {
							uni.reLaunch({
							  url: "/pages/login/loginWechat"
							})
						}, 1000);
					}
				 }
			},
			//列表
			async allowanceList(page){
				const [err, res] = await api.allowanceList({
					query: {
						page:page,
						status:this.current,
						limit:10
					},
					 header:{
						'Content-Type': 'application/json',
						'token': this.token
					 }
				 });
				 console.log(res)
				 if(res.data.code == 0){
					 if(this.current==0){
						 this.list = [...this.list, ...res.data.data.list];
						 this.totalPage=res.data.data.totalPage
						 if(this.list.length==0){
							  this.loadMoreText = "暂无数据!"
							 this.showLoadMore = true;
						}else{
							this.showLoadMore = false; 
						}
					 }else if(this.current==1){
						 this.listOne = [...this.listOne, ...res.data.data.list];
						 this.totalPage=res.data.data.totalPage
						 if(this.listOne.length==0){
							  this.loadMoreText = "暂无数据!"
							 this.showLoadMore = true;
						}else{
							this.showLoadMore = false; 
						}
					 }else if(this.current==2){
						 this.listTwo = [...this.listTwo, ...res.data.data.list];
						 this.totalPage=res.data.data.totalPage
						  if(this.listTwo.length==0){
						 	  this.loadMoreText = "暂无数据!"
						 	 this.showLoadMore = true;
						 }else{
						 	this.showLoadMore = false; 
						 }
					 }else{
						 this.listThree = [...this.listThree, ...res.data.data.list];
						 this.totalPage=res.data.data.totalPage
						 if(this.listThree.length==0){
							  this.loadMoreText = "暂无数据!"
							 this.showLoadMore = true;
						}else{
							this.showLoadMore = false; 
						}
					 }
				 }else{
					uni.showToast({
					 	title: res.data.msg,
					 	icon: 'none'
					 })
					if(res.data.code==200){
						uni.removeStorageSync('token');
						setTimeout(() => {
							uni.reLaunch({
							  url: "/pages/login/loginWechat"
							})
						}, 1000);
					}
				 }
			},
			GetQueryString(name){
			    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
			    var r = window.location.search.substr(1).match(reg);
			    if(r!=null)return  unescape(r[2]); return null;
			},
			//团建规则
			async searchByType(){
				const [err, res] = await api.searchByType({
					 query: {
						type:'league'
					 }
				 });
				if(res.data.code == 0){
					this.centerGz=res.data.data
				}
			},
			onClickItem(index) {
				if (this.current !== index) {
					this.current = index
					this.page=1
					this.list=[]
					this.listOne=[]
					this.listTwo=[]
					this.listThree=[]
					this.allowanceList(this.page)
				}
			},
			//点击显示规则
			guizeShow(){
			  this.gzShow=true
			  this.searchByType()
			},
			//点击隐藏规则
			guizeHide(){
			  this.gzShow=false
			},
			add(){
				uni.navigateTo({
				  url: "/pages/league/leagueAdd/leagueAdd"
				})
			},
			obj(id){
				console.log(id)
				uni.navigateTo({
				  url: "/pages/league/leagueInfo/leagueInfo?id="+id
				})
			}
		}
	}
</script>
